import {
  reportStatus,
  STATUS_TYPE_DRAFT,
  STATUS_TYPE_PENDING,
  STATUS_TYPE_APPROVED,
  STATUS_TYPE_REVIEW,
  STATUS_TYPE_FINISH,
  reportColorStatus,
  isPassedColorStatus
} from '@/views/formConst'

export function tableColumns() {
  let list = [
    {
      title: '表单名称',
      key: 'name',
      align: 'center',
      minWidth: 180
    },
    {
      title: '类型',
      key: 'subType',
      align: 'center'
    },
    {
      title: '申报标题',
      key: 'title',
      align: 'center',
      minWidth: 180
    },
    {
      title: '单位',
      key: 'org',
      minWidth: 100,
      render: (h, params) => {
        return h(
          'Tooltip',
          {
            props: {
              content: this.treeData.find(item => item.orgCode === params.row.org)?.orgName || '--',
              placement: 'bottom',
              transfer: true
            }
          },
          [
            h('span', {}, this.treeData.find(item => item.orgCode === params.row.org)?.orgName || '--') // 实际的DOM内容
          ]
        )
      }
    },
    {
      title: '联系人',
      key: 'contact',
      align: 'center'
    },
    {
      title: '联系电话',
      key: 'phone',
      align: 'center',
      width: 120
    },
    {
      title: '联系邮箱',
      key: 'email',
      align: 'center'
    },
    {
      title: '当前填报周期',
      key: 'period',
      align: 'center'
    },
    {
      title: '更新时间',
      key: 'updateTime',
      width: 180,
      align: 'center'
    },
    {
      title: '状态',
      render: (h, params) => {
        let color = reportColorStatus[params.row.status]
        let name = reportStatus.find(item => item.key === params.row.status).name || '--'
        return h(
          'div',
          {
            style: {
              display: 'flex',
              'justify-content': 'center',
              'align-items': 'center'
            }
          },
          [
            h('div', {
              style: {
                margin: '4px',
                width: '6px',
                height: '6px',
                'background-color': color /* 圆点颜色 */,
                'border-radius': '50%' /* 圆形 */
              }
            }),
            name
          ]
        )
      }
    },
    {
      title: '操作',
      align: 'left',
      fixed: 'right',
      width: 150,
      render: (h, params) => {
        return h('RowTools', {
          props: {
            data: [
              {
                type: 'text',
                text: '编辑',
                optType:
                  this.formPermissions[params.row.formId].operate &&
                  [STATUS_TYPE_DRAFT, STATUS_TYPE_PENDING].includes(params.row.status) &&
                  params.row.createBy === this.userCode
                    ? ''
                    : 'ashing',
                handle: () => {
                  this.editForm(params.row)
                }
              },
              {
                type: 'text',
                text: '详情',
                optType:
                  this.formPermissions[params.row.formId].view &&
                  ![STATUS_TYPE_DRAFT, STATUS_TYPE_PENDING].includes(params.row.status)
                    ? ''
                    : 'ashing',
                handle: () => {
                  this.viewForm(params.row)
                }
              }
              // 隐藏评选按钮
              // {
              //   type: 'text',
              //   text: '评选',
              //   hidden: !this.hasPermission('FORM_CREATE'),
              //   optType:
              //     this.operateIds.includes(this.userCode) &&
              //     params.row.isPassed != 1 &&
              //     params.row.isPassed != 0 &&
              //     [STATUS_TYPE_APPROVED].includes(params.row.status)
              //       ? ''
              //       : 'ashing',
              //   handle: () => {
              //     this.editPass(params.row)
              //   }
              // }
            ]
          }
        })
      }
    }
  ]
  return list
}

export function ownerColumns() {
  let list = [
    {
      title: '表单名称',
      key: 'name',
      align: 'center',
      minWidth: 180
    },
    {
      title: '类型',
      key: 'subType',
      align: 'center'
    },
    {
      title: '申报标题',
      key: 'title',
      align: 'center',
      minWidth: 180
    },
    {
      title: '单位',
      key: 'org',
      minWidth: 100,
      render: (h, params) => {
        return h(
          'Tooltip',
          {
            props: {
              content: this.treeData.find(item => item.orgCode === params.row.org)?.orgName || '--',
              placement: 'bottom',
              transfer: true
            }
          },
          [
            h('span', {}, this.treeData.find(item => item.orgCode === params.row.org)?.orgName || '--') // 实际的DOM内容
          ]
        )
      }
    },
    {
      title: '联系人',
      key: 'contact',
      align: 'center'
    },
    {
      title: '联系电话',
      key: 'phone',
      align: 'center',
      width: 120
    },
    {
      title: '联系邮箱',
      key: 'email',
      align: 'center'
    },
    {
      title: '当前填报周期',
      key: 'period',
      align: 'center'
    },
    {
      title: '更新时间',
      key: 'updateTime',
      width: 180,
      align: 'center'
    },
    {
      title: '状态',
      render: (h, params) => {
        let color = reportColorStatus[params.row.status]
        let name = reportStatus.find(item => item.key === params.row.status).name || '--'
        return h(
          'div',
          {
            style: {
              display: 'flex',
              'justify-content': 'center',
              'align-items': 'center'
            }
          },
          [
            h('div', {
              style: {
                margin: '4px',
                width: '6px',
                height: '6px',
                'background-color': color /* 圆点颜色 */,
                'border-radius': '50%' /* 圆形 */
              }
            }),
            name
          ]
        )
      }
    },
    {
      title: '得分',
      key: 'score',
      align: 'center'
    },
    {
      title: '是否通过',
      width: 100,
      align: 'center',
      render: (h, params) => {
        let color = isPassedColorStatus[params.row.isPassed]
        let passed = this.isPassedList.find(item => item.key === params.row.isPassed)
        let name = '--'
        if (passed) {
          name = passed.name
        }
        return h(
          'div',
          {
            style: {
              marginRight: '20px',
              display: 'flex',
              justifyContent: 'center',
              alignItems: 'center'
            }
          },
          [
            h('div', {
              style: {
                margin: '4px',
                width: '6px',
                height: '6px',
                'background-color': color /* 圆点颜色 */,
                'border-radius': '50%' /* 圆形 */
              }
            }),
            name
          ]
        )
      }
    },
    {
      title: '操作',
      align: 'left',
      fixed: 'right',
      width: 150,
      render: (h, params) => {
        return h('RowTools', {
          props: {
            data: [
              {
                type: 'text',
                text: '编辑',
                optType:
                  this.formPermissions[params.row.formId].operate &&
                  [STATUS_TYPE_DRAFT, STATUS_TYPE_PENDING].includes(params.row.status) &&
                  params.row.createBy === this.userCode
                    ? ''
                    : 'ashing',
                handle: () => {
                  this.editForm(params.row)
                }
              },
              {
                type: 'text',
                text: '详情',
                optType:
                  this.formPermissions[params.row.formId].view &&
                  ![STATUS_TYPE_DRAFT, STATUS_TYPE_PENDING].includes(params.row.status)
                    ? ''
                    : 'ashing',
                handle: () => {
                  this.viewForm(params.row)
                }
              }
              // 隐藏评选按钮
              // {
              //   type: 'text',
              //   text: '评选',
              //   hidden: !this.hasPermission('FORM_CREATE'),
              //   optType:
              //     this.operateIds.includes(this.userCode) &&
              //     params.row.isPassed != 1 &&
              //     params.row.isPassed != 0 &&
              //     [STATUS_TYPE_APPROVED].includes(params.row.status)
              //       ? ''
              //       : 'ashing',
              //   handle: () => {
              //     this.editPass(params.row)
              //   }
              // }
            ]
          }
        })
      }
    }
  ]
  return list
}
